package com.javaclimb.mappers;

import com.javaclimb.pojo.SelectTree;
import com.javaclimb.pojo.Tree;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TreeMapper {
    /*查询所有树的信息*/
    List<Tree> selectAllTree();

    /**
     * 获取前十棵古树
     */
    List<Tree> selectHotTreeTopTen();

    /**
     * tree条件分页查询
     * @return List<Tree>
     */
    //@Select("select * from user")
    //条件动态查询，使用xml映射文件（动态sql）
    public List<Tree> list(String city,String district,String level,String treeType,String growthStatus,String code);

    //根据编号/地址/等级/种类分页查询  编号是模糊查询，其他条件通过联级选择器精准选择
    List<Tree> selectByKeys(Tree tree);

    /**
     * 批量删除
     * @param  ids
     */
    //使用了xml
    void delete01(List<Integer> ids);
    void delete02(List<Integer> ids);

    @Insert("INSERT INTO tree_ms001_1000(code,chinese_name,tree_type,level,age,family,genus,location,city,district,lon,lat,img_file_path) " +
            "VALUES(#{code},#{chineseName},#{treeType},#{level},#{age},#{family},#{genus},#{location},#{city},#{district},#{lon},#{lat},#{imgFilePath})")
    void insert01(Tree tree);
    @Insert("INSERT INTO tree_ms002_1000(code,chinese_name,other_name,latin_name,feature,slope_aspect,slope_degree,slope_position,soil_name,soil_stiffness,growth_status,growth_environment,history,protection_status,is_public,oddity_descriptions" +
            ",height,dbh,canopy_average,canopy_east_west,canopy_south_north,altitude,real_age,estimate_age) " +
            "VALUES(#{code},#{chineseName},#{otherName},#{latinName},#{feature},#{slopeAspect},#{slopeDegree},#{slopePosition},#{soilName},#{soilStiffness},#{growthStatus},#{growthEnvironment},#{history},#{protectionStatus},#{isPublic},#{oddityDescriptions}" +
            ",#{height},#{dbh},#{canopyAverage},#{canopyEastWest},#{canopySouthNorth},#{altitude},#{realAge},#{estimateAge})")
    void insert02(Tree tree);

    //根据id查询单个员工
    @Select("select * from tree_ms001_1000 where id=#{id}")
    Tree getId01(Integer id);
    @Select("select * from tree_ms002_1000 where code = (select code from tree_ms001_1000 where id =#{id})")
    Tree getId02(Integer id);//根据getId01封装的数据继续封装02表的数据

    /**
     * 更新员工
     * 使用xml映射文件
     */
    void update01(Tree tree);
    void update02(Tree tree);

    /**
     * 根据树id查询点赞数量
     */
    int addLike(Integer id);

    int getLike(Integer id);

    int addVisit(Integer id);

    int queryVisitsById(Integer id);

    List<Tree> getTreeByInput(String q);
}
